/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package org.agilelang.editor.view.filesystem;

/**
 *
 * @author RoderickNestor
 */
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */


/**
 *
 * @author RoderickNestor
 */
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.*;
import java.io.*;
import javax.swing.tree.*;

public class MyPanel1  implements Runnable {

    private JTree tree = new JTree();
 JScrollPane treeScroll;// = new JScrollPane(tree);

    public JScrollPane getTreeScroll() {
        return treeScroll;
    }

    public void setTreeScroll(JScrollPane treeScroll) {
        this.treeScroll = treeScroll;
    }
    public JTree getTree() {
        return tree;
    }

    public void setTree(JTree tree) {
        this.tree = tree;
    }
    private SimpleFileManager simpleFileManager;
    

    public MyPanel1(String path) throws IOException {
        //add(new JScrollPane(tree)); 
        treeScroll = new JScrollPane(tree);
        File root = new File(path);
        simpleFileManager = new SimpleFileManager(root, new ImageFileFilter());
        tree.setModel(new DefaultTreeModel(simpleFileManager.getDirectoryTree()));       
    }
    
    public void  listener(MouseListener ml){
        tree.addMouseListener(ml);
    }

  // This has to be a separate method, because it is dangerous to leak
    // a "this" pointer from a constructor!
    public void activateMonitor() {
        simpleFileManager.startMonitoring();
        FileMonitor fileMonitor = simpleFileManager.getFileMonitor();
        fileMonitor.addClient(this);

    }

  // The FileManager will call the run() method from the eventqueue, when
    // the tree needs to be rebuild.
    public void run() {
        simpleFileManager.refresh();
        tree.setModel(new DefaultTreeModel(simpleFileManager.getDirectoryTree()));
    }

    // Just for testing
    
}
